home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WarriorsProgress.sit / Warrior’s Progress / source code / Source / Libraries / Files / Directory.cp < prev    next >
Text File  |  1997-06-28  |  1KB  |  65 lines

  1. // Directory.cp
  2.  
  3. #ifndef Directory_h
  4. #include "Directory.h"
  5. #endif
  6. #ifndef CatInfo_h
  7. #include "CatInfo.h"
  8. #endif
  9. #ifndef NotADirectoryError_h
  10. #include "NotADirectoryError.h"
  11. #endif
  12. #ifndef DirectoryNotFoundError_h
  13. #include "DirectoryNotFoundError.h"
  14. #endif
  15.  
  16. void Directory::Up()
  17.   {
  18.     Assert( !IsRoot() );
  19.     CatInfo info( *this );
  20.     id = info.Location().ParentID();
  21.   }
  22.  
  23. void Directory::Down( ConstPString name )
  24.   {
  25.     CatInfo info( *this, name );
  26.  
  27.     if ( !info.IsDirectory() )
  28.         throw NotADirectoryError( noErr );
  29.     
  30.     volume = info.Location().Volume();
  31.     id = info.Directory().ID();
  32.   }
  33.  
  34. Directory Directory::Parent() const
  35.   {
  36.     Assert( !IsRoot() );
  37.     CatInfo info( *this );
  38.     return info.Location().Parent();
  39.   }
  40.  
  41. Directory Directory::Find( VolumeID volume,
  42.                                     OSType folder,
  43.                                     bool creating )
  44.   {
  45.     int16 volumeFound;
  46.     int32 directoryFound;
  47.     OSErr error = FindFolder( volume.RefNum(),
  48.                                       folder,
  49.                                       creating,
  50.                                       &volumeFound,
  51.                                       &directoryFound );
  52.     
  53.     switch ( error )
  54.       {
  55.         case fnfErr:    throw DirectoryNotFoundError( error );
  56.         case dupFNErr:    throw NotADirectoryError( error );
  57.       }
  58.     
  59.     if ( error != noErr )
  60.         throw FileError( error );
  61.      
  62.     return Directory( VolumeID::Make( volumeFound ),
  63.                             DirectoryID::Make( directoryFound ) );
  64.   }
  65.